package entity

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

// Conversation 对话模型
type Conversation struct {
	ID        uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
	UserID    uuid.UUID `gorm:"not null;index"`
	Title     string    `gorm:"not null;size:500"`
	CreatedAt time.Time `gorm:"autoCreateTime"`
	UpdatedAt time.Time `gorm:"autoUpdateTime"`

	// 关联
	User *User `gorm:"foreignKey:UserID"`
}

// TableName specifies the table name for the Conversation model.
func (Conversation) TableName() string {
	return "conversations"
}

// BeforeCreate 在创建之前设置UUID
func (c *Conversation) BeforeCreate(tx *gorm.DB) error {
	if c.ID == uuid.Nil {
		c.ID = uuid.New()
	}
	return nil
}
